﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;

namespace CeA.Reports.Atendimento.DataAccess.Helpers {
    public class AuthenticationHelper {
        /// <summary>
        /// Calcular o hash MD5 da senha de um usuário.
        /// </summary>
        /// <param name="senha">The senha.</param>
        /// <returns></returns>
        public static string CalcularHashSenha(string senha) {
            MD5 md5 = MD5.Create();
            byte[] input = Encoding.ASCII.GetBytes(senha);
            byte[] hash = md5.ComputeHash(input);

            StringBuilder hex = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
                hex.Append(hash[i].ToString("X2"));

            return hex.ToString();
        }
    }
}
